import cn.hutool.core.util.HexUtil;

import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;

public class q {
    public static void main(String[] args) throws Exception {
        String sKey = "482737d7ad3f29a2b43e733458303858";
        String sSrc = "{\"tracks\":[{\"track\":\"LXBMY000027520879\",\"key\":\"global.cainiao.com\"}],\"uuid\":\"0.020646836390068035-1641893877000\",\"noCache\":false,\"isChoose\":false,\"webDateTime\":\"2022-01-11 17:37:57\"}";

        String iv = "TRACK718-QWER789";


//        SecretKeySpec skeySpec = createKey(sKey);
//        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");//"算法/模式/补码方式"
//        AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
//        parameters.init(new IvParameterSpec(iv));
//
//        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, parameters);
//        byte[] encrypted = cipher.doFinal(sSrc.getBytes(StandardCharsets.UTF_8));
//        String encode = new BASE64Encoder().encode(encrypted);//此处使用BASE64做转码功能，同时能起到2次加密的作用。
//        System.out.println(encode);

//        byte[] encrypt = new AES().encrypt(sSrc.getBytes(StandardCharsets.UTF_8), sKey.getBytes(StandardCharsets.UTF_8));
//        System.out.println(new String(encrypt));
        System.out.println(new String(HexUtil.decodeHex("3534353234313433346233373331333832643531353734353532333733383339")));
    }


    private static SecretKeySpec createKey(String password) {
        byte[] data = null;
        if (password == null) {
            password = "";
        }
        StringBuffer sb = new StringBuffer(32);
        sb.append(password);
        while (sb.length() < 32) {
            sb.append("0");
        }
        if (sb.length() > 32) {
            sb.setLength(32);
        }

        try {
            data = sb.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return new SecretKeySpec(data, "AES");
    }

    public static String create32Key(String password) {
        StringBuffer sb = new StringBuffer(32);
        sb.append(password);
        while (sb.length() < 32) {
            sb.append("0");
        }
        if (sb.length() > 32) {
            sb.setLength(32);
        }
        return sb.toString();
    }
}
